import pandas as pd
import matplotlib.pyplot as plt

plt.rcParams['font.sans-serif'] = ['Arial Unicode MS']
df = pd.read_csv('data/birds.csv')
anser = df[df['Genus'] == 'Anser'].copy()
anser['平均体长'] = (anser['MinLength'] + anser['MaxLength']) / 2
anser['平均体重'] = (anser['MinBodyMass'] + anser['MaxBodyMass']) / 2
anser['平均翼展'] = (anser['MinWingspan'] + anser['MaxWingspan']) / 2
names = list(anser['Name'])

plt.figure(figsize=(8, 4))
plt.bar(names, anser['MinLength'], label='最小体长')
plt.bar(names, anser['MaxLength'], alpha=0.6, label='最大体长')
plt.ylabel('厘米')
plt.xticks(rotation=45, ha='right')
plt.legend()
plt.tight_layout()
plt.savefig('第三次作业_第一题_图1.png', dpi=300)
plt.close()

plt.figure(figsize=(8, 4))
plt.bar(names, anser['MinBodyMass'], label='最小体重')
plt.bar(names, anser['MaxBodyMass'], alpha=0.6, label='最大体重')
plt.ylabel('克')
plt.xticks(rotation=45, ha='right')
plt.legend()
plt.tight_layout()
plt.savefig('第三次作业_第一题_图2.png', dpi=300)
plt.close()

plt.figure(figsize=(6, 4))
plt.scatter(anser['平均体重'], anser['平均翼展'])
for i in range(len(names)):
    plt.text(anser['平均体重'].iloc[i] + 30, anser['平均翼展'].iloc[i] + 0.5, names[i])
plt.xlabel('平均体重(克)')
plt.ylabel('平均翼展(厘米)')
plt.tight_layout()
plt.savefig('第三次作业_第一题_图3.png', dpi=300)
plt.close()
